<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<button type="button" class="btn btn-primary" onclick="toAdd()">添加</button>
	<table class="table">

		<tr>
			<th>id <input type="checkbox" id="ids">	</th>
			<th>名称</th>
			<th>图片</th>
			<th>品牌</th>
			<th>分类</th>
			<th>上架</th>
			<th>标题</th>
			<th>操作</th>
		</tr>
		<c:forEach items="${page.list }" var="item">
			<tr>
				<td>${item.id}<input type="checkbox" id="id" value="${item.id}"></td>
				<td>${item.goodsName}</td>
				<%-- <td><img alt="" src="/pic/${item.smallPic}" width="40"
					height="40"></td> --%>
					<td><img src="data:image/jpg;base64,${item.smallPic}" width="40"
					height="40"></td>
				<td>${item.brand}</td>
				<td>${item.category}</td>
				<td>${item.isMarketable==1?'上架':'未上架'}</td>
				<td>${item.caption}</td>
				<td>
					<button type="button" onclick="toupdate(${item.id})">修改</button>
					<button>删除</button>
					<button onclick="addSku(${item.id})">添加sku</button>
				</td>
			</tr>
		</c:forEach>

		<tr>
			<td align="center" colspan="3"><a
				href="javascript:goPage(${page.firstPage })">首页</a>
				&nbsp;&nbsp;&nbsp;&nbsp; <a
				href="javascript:goPage(${page.prePage })">上一页</a>
				&nbsp;&nbsp;&nbsp;&nbsp; <a
				href="javascript:goPage(${page.nextPage })">下一页</a>
				&nbsp;&nbsp;&nbsp;&nbsp; <a
				href="javascript:goPage(${page.pages })">尾页</a></td>
		</tr>
	</table>
	<script type="text/javascript">
		function toAdd(){
			$("#content").load("./spu/toAdd")
		}
		function goPage(page) {
			
			$("#content").load("./spu/list?currPage=" + page)
		}
		var index = 0
		function addOption() {
			$("#dynamic").append(
					'<div class="form-group">'
					+'<label for="recipient-name" class="col-form-label">属性:'
					+'<button type="button" class="btn btn-link" onclick="delOption(this)">删除</button>'
					+'</label>'
					+'<input type="text" class="form-control" name="options['+index+'].optionName">'
					+'</div>'
				)
			index++;
		}
		function delOption(element) {
			$(element).parent().parent().remove();
		}
		function saveSpec() {
			$.post('./spec/saveSpec',$("#addForm").serialize(),function(data){
				if(data){
					$('#addModal').modal('hide')
					//$("#content").load('./spec/list?currPage=1')
				}else{
					alert("保存失败")
				}
			},'json')
		}
		function addSku(spuId){
			$("#content").load('./sku/toAdd?spuId='+spuId)
		}
	</script>
</body>
</html>